#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int minimumDifference(vector<int> &nums, int k)
    {
        int ans = INT_MAX;
        for (int i = 0; i < nums.size(); i++)
        {
            // check [i,i]
            ans = min(abs(k - nums[i]), ans);
            for (int j = i - 1; j >= 0; j--)
            {
                // range[j,i]
                int c = nums[j] | nums[j + 1];
                if (c == nums[j])
                    break;
                nums[j] = c;
                ans = min(abs(k - c), ans);
            }
        }
        return ans;
    }
};

int main()
{
    cout << "Code3171" << endl;
    Solution s;
    vector<int> nums = {1, 2, 4, 5};
    cout << s.minimumDifference(nums, 3) << endl;
    return 0;
}